<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=1.0, minimum-scale=1.0, maximum-scale=1.0" />
	<title>工单列表</title>
	<link rel="stylesheet" type="text/css" href="common.css">
	<link rel="stylesheet" type="text/css" href="layer.css">
</head>
<body class="listcss">
	<a href="grabdetail.html" class=""></a>
	<!-- <div class="com-list">
		<div class="list-head">
			<label>工单号:2018213540512</label>
			<span>未完成</span>
		</div>
		<div class="list-content">
			<span class="mowrap">工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述</span>
		</div>
		<div class="btngroup">
			<a href="grabdetail.html">
				<div class="combtn" style="border-right: 1px solid #d6d6d6;color: #04a3ff;">详情</div>
			</a>
			<div class="combtn grabbtn">抢单</div>
		</div>
	</div>

	<div class="com-list">
		<div class="list-head">
			<label>工单号:2018213540512</label>
			<span>未完成</span>
		</div>
		<div class="list-content">
			<span class="mowrap">工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述工单简述</span>
		</div>
		<div class="btngroup">
			<a href="grabdetail.html">
				<div class="combtn" style="border-right: 1px solid #d6d6d6;color: #04a3ff;">详情</div>
			</a>
			<div class="combtn grabbtn">抢单</div>
		</div>
	</div> -->

	<!-- 底部导航栏 -->
	<div class="bottomfix">
		<a href="#"><div class="botbtn" style="border-right: 1px solid #d6d6d6;color: #deaa48;">工单池</div></a>
		<a href="order.html"><div class="botbtn" style="border-right: 1px solid #d6d6d6;">个人工单</div></a>
		<a href="person.html"><div class="botbtn">个人中心</div></a>
	</div>

	<!-- 弹层 -->
	<div class="tips">
		抢单成功
	</div>
	<script src="js/jquery-1.8.3.min.js"></script>
	<script src="js/common.js"></script>
	<script type="text/javascript" src="layer.js"></script>
	<script type="text/javascript">
		/* $(function(){
			$(".grabbtn").click(function(){
				$(".tips").show();
				setInterval(function(){ 
					window.location.href="order.html";
				}, 2000);
				
			})
		}) */
		
		$.ajax({
			type:"POST",
			url:"../Handle/getHandle",
			contentType : "application/json;charset=UTF-8",
			dataType:"Json",
			success:function(res){
				var info = res.info;
				var data = res.object;
				if(info=="success"){
				}else{
					window.location.href="login.html";
				}
			}
		})

		function refresh(){
		    window.location.reload();//刷新当前页面.
		     
		}
		
		$.ajax({
			type:"POST",
			url:"../Job/jobPool",
			contentType : "application/json;charset=UTF-8",
			dataType:"Json",
			success:function(res){
				var info = res.info;
				if(info=="success"){
					 var str = '';
	                 var data = res.object;
	                 for (var i = 0, len = data.length; i < len; i++) {
	                	 str += '<div class="com-list"><div class="list-head"><label>工单号:'+ data[i].job_id +'</label>';
						 str += '<span>'+ data[i].job_state +'</span></div><div class="list-content">';
						 str += '<span class="mowrap">'+ data[i].detail + '</span></div>';
						 str += '<div class="btngroup"><a href="grabdetail.html?id=' + data[i].job_id + '">';
						 str += '<div class="combtn" style="border-right: 1px solid #d6d6d6;color: #04a3ff;">详情</div></a>';
						 str += '<div class="combtn grabbtn" data-name="' + data[i].job_id + '">抢单</div></div></div>';
	                 }
	                 $("body").append(str)	
	                 $("body").click(function(event) {
	                	 if($(event.target).hasClass("grabbtn")){
	                		 var job_id = $(event.target).attr("data-name");
		                	 console.log(job_id)
		                	 $.ajax({
		                		type:"POST",
		             			url:"../Job/grapJob",
		             			data:{job_id:job_id},
		             			dataType:"Json",
		             			success:function(res){
		             				if(res.info == "success"){
		             					$(".tips").show();
		             					setInterval(function(){ 
		             						window.location.href="order.html";
		             					}, 2000);
		             				}else{
		             					layer.open({
		        		                    style:'top:-2rem',
		        		                    content: '抢单失败'
		        		                    ,skin: 'msg'
		        		                    ,time: 2 //2秒后自动关闭
		        		                });
		             				}
		             			}
		                	 })
	                	 }
	                 })
				}else if(info=="false"){
					 var str = '暂无工单';
					 $("body").append(str)	
				}
			}
		});
	</script>
</body>
</html>